package com.shunan.miaosha.exception;

import org.springframework.validation.BindException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import com.shunan.miaosha.result.CodeMsg;
import com.shunan.miaosha.result.Result;

@ControllerAdvice
@ResponseBody
public class GlobalExceptionHandler {
	
	@ExceptionHandler(value=Exception.class)
	public Result<String> handlerException(Exception e){
		e.printStackTrace();
		
		if(e instanceof BindException){
			return Result.error(CodeMsg.PARAM_ERROR);
		}else if(e instanceof CanNotFindUserException){
			return Result.error(CodeMsg.NO_USER);
		}else{
			return Result.error(CodeMsg.SERVER_ERROR);
		}
	}
	
}
